package com.dormitory.dormitorymanagement.controller;

import com.dormitory.dormitorymanagement.pojo.PageBean;
import com.dormitory.dormitorymanagement.pojo.Result;
import com.dormitory.dormitorymanagement.pojo.StudentEvaluations;
import com.dormitory.dormitorymanagement.pojo.dto.NoticeDto;
import com.dormitory.dormitorymanagement.pojo.dto.UploadTimeTableDto;
import com.dormitory.dormitorymanagement.service.ClassLeaderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/classLeader")
@CrossOrigin(origins = "http://localhost:8081", allowedHeaders = "*")
public class ClassLeaderController {


    @Autowired
    ClassLeaderService classLeaderService;
    @PostMapping("/notice")
    public Result notice(@RequestBody NoticeDto noticeDto) {
        classLeaderService.notice(noticeDto);
        return Result.success();
    }



    @PostMapping("/uploadTimetable")
    public Result uploadTimetable(
            @RequestParam("semester") String semester,
            @RequestParam("remark") String remark,
            @RequestParam("file") MultipartFile file,
            @RequestParam("studentId") String studentId
    ) {

        UploadTimeTableDto  uploadTimeTableDto = new UploadTimeTableDto();
        uploadTimeTableDto.setSemester(semester);
        uploadTimeTableDto.setRemark(remark);
        uploadTimeTableDto.setFile(file);
        uploadTimeTableDto.setStudentId(studentId);
        try {
            classLeaderService.saveTimetable(uploadTimeTableDto);
            return Result.success("课表上传成功");
        } catch (Exception e) {
            return Result.error("上传失败：" + e.getMessage());
        }
    }

    @GetMapping("/classmateevaluation")
    public Result<PageBean<StudentEvaluations>>  getStudentClassmateEvaluations(@RequestParam String studentId, @RequestParam Integer page, @RequestParam Integer pageSize){

        return Result.success(classLeaderService.getStudentClassmateEvaluations(studentId,page,pageSize));
    }

}
